/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.form.client.form.impl;

import com.genia.toolbox.web.gwt.basics.client.i18n.GwtI18nMessage;
import com.genia.toolbox.web.gwt.basics.client.support.GwtObjectUtils;
import com.genia.toolbox.web.gwt.form.client.form.MutableItem;

/**
 * this abstract class represent a {@link MutableItem}.
 */
public abstract class AbstractItem
    extends AbstractForm
    implements MutableItem
{

  /**
   * the enable state.
   */
  private boolean enabled = true;

  /**
   * the i18nMessage.
   */
  private GwtI18nMessage labelKey;



  /**
   * Indicates whether some other object is "equal to" this one.
   * 
   * @param obj
   *          the reference object with which to compare.
   * @return <code>true</code> if this object is the same as the obj argument;
   *         <code>false</code> otherwise.
   * @see java.lang.Object#equals(java.lang.Object)
   */
  @Override
  public boolean equals(final Object obj)
  {
    if (this == obj) {
      return true;
    }

    if (obj == null) {
      return false;
    }

    if (!super.equals(obj)) {
      return false;
    }

    if (obj instanceof AbstractItem) {
      AbstractItem simpleItem = (AbstractItem) obj;

      if (!GwtObjectUtils.nullSafeEquals(getLabelKey(), simpleItem.getLabelKey())) {
        return false;
      }

      return isEnabled() == simpleItem.isEnabled();
    }

    return false;

  }



  /**
   * getter for the labelKey property.
   * 
   * @return the labelKey
   */
  public GwtI18nMessage getLabelKey()
  {
    return labelKey;
  }



  /**
   * Returns a hash code value for the object. This method is supported for the
   * benefit of hashtables such as those provided by
   * <code>java.util.Hashtable</code>.
   * 
   * @return a hash code value for this object.
   * @see java.lang.Object#hashCode()
   */
  @Override
  public int hashCode()
  {
    return GwtObjectUtils.nullSafeHashCode(new Object[] { new Integer(super.hashCode()), getLabelKey(), new Boolean(isEnabled()) });
  }



  /**
   * getter for the enabled property.
   * 
   * @return the enabled
   */
  public boolean isEnabled()
  {
    return enabled;
  }



  /**
   * setter for the enabled property.
   * 
   * @param enabled
   *          the enabled to set
   */
  public void setEnabled(boolean enabled)
  {
    this.enabled = enabled;
  }



  /**
   * setter for the labelKey property.
   * 
   * @param labelKey
   *          the labelKey to set
   */
  public void setLabelKey(GwtI18nMessage labelKey)
  {
    this.labelKey = labelKey;
  }

}
